<template>
	<view class="trading">
		<view class="trading-buy-list">
			<block v-for="(item, index) in myBuyIngList" :key="index">
				<view class="tbl-item">
					<view class="item buy-type one">
						{{ item.formatDate }}
					</view>
					<view class="item">{{ item.nums }}</view>
					<view class="item">{{ item.price }}</view>
					<view class="item">{{ item.totalPrice }}</view>
					<view class="item" :class="item.states.color">{{ item.states.name }}</view>
					<view class="item color6" @tap="onCalloff(item.id, index)">撤单</view>
				</view>
			</block>
			<view class="load-more-end">
				没有更多数据
			</view>
		</view>
	</view>
</template>

<script>
import { tradingState } from '../../../../../common/utils/state.js'
export default {
	props: {
		activeTAB: {
			type: Number
		}
	},
	data() {
		return {
			myBuyIngList: []
		};
	},
	onShow() {
	},
	methods: {
		myBuyIng() {
			uni.showLoading({
				title: ''
			});
			this.$http.myBuy().then(res => {
				uni.hideLoading();
				const data = res.data;
				if (data.success) {
					this.myBuyIngList = data.data;
					if (data.data.length > 0) {
						data.data.forEach(e => {
							e.states = tradingState(e.state, e)
						})
					}
					return;
				}
				uni.showToast({
					title: data.errMsg,
					icon: 'none'
				});
			});
		},
		onCalloff (id, index) {
			uni.showModal({
				title: '提示',
				content: '确定撤销订单？',
				success: (res) => {
					if (res.confirm) {
						uni.showLoading({
							title: '撤销中...'
						});
						this.$http.calloff({
							id: id
						}).then(res => {
							uni.hideLoading();
							const data = res.data;
							if (data.success) {
								uni.showToast({
									title: '撤销成功'
								});
								this.$delete(this.myBuyIngList, index)
								return;
							}
							uni.showToast({
								title: data.errMsg,
								icon: 'none'
							});
						})
						return
					}
				}
			})
		}
	}
};
</script>

<style scoped lang="scss">
@import './tabs.scss';
</style>
